package l1j.server.echo;
import static l1j.server.echo.OpcodesClient.*;



import l1j.server.server.clientpackets.C_AddBookmark;
import l1j.server.server.clientpackets.C_AddBuddy;
import l1j.server.server.clientpackets.C_Amount;
import l1j.server.server.clientpackets.C_Attack;
import l1j.server.server.clientpackets.C_Attr;
import l1j.server.server.clientpackets.C_AuthLogin;
import l1j.server.server.clientpackets.C_BanClan;
import l1j.server.server.clientpackets.C_BanParty;
import l1j.server.server.clientpackets.C_Board;
import l1j.server.server.clientpackets.C_BoardBack;
import l1j.server.server.clientpackets.C_BoardDelete;
import l1j.server.server.clientpackets.C_BoardRead;
import l1j.server.server.clientpackets.C_BoardWrite;
import l1j.server.server.clientpackets.C_Buddy;
import l1j.server.server.clientpackets.C_CallPlayer;
import l1j.server.server.clientpackets.C_ChangeHeading;
import l1j.server.server.clientpackets.C_ChangeWarTime;
import l1j.server.server.clientpackets.C_CharReset;
import l1j.server.server.clientpackets.C_CharcterConfig;
import l1j.server.server.clientpackets.C_Chat;
import l1j.server.server.clientpackets.C_ChatParty;
import l1j.server.server.clientpackets.C_ChatWhisper;
import l1j.server.server.clientpackets.C_CheckPK;
import l1j.server.server.clientpackets.C_Clan;
import l1j.server.server.clientpackets.C_CommonClick;
import l1j.server.server.clientpackets.C_CreateChar;
import l1j.server.server.clientpackets.C_CreateClan;
import l1j.server.server.clientpackets.C_CreateParty;
import l1j.server.server.clientpackets.C_DelBuddy;
import l1j.server.server.clientpackets.C_DeleteBookmark;
import l1j.server.server.clientpackets.C_DeleteChar;
import l1j.server.server.clientpackets.C_DeleteInventoryItem;
import l1j.server.server.clientpackets.C_Deposit;
import l1j.server.server.clientpackets.C_Door;
import l1j.server.server.clientpackets.C_Drawal;
import l1j.server.server.clientpackets.C_DropItem;
import l1j.server.server.clientpackets.C_Emblem;
import l1j.server.server.clientpackets.C_EnterPortal;
import l1j.server.server.clientpackets.C_Exclude;
import l1j.server.server.clientpackets.C_ExitGhost;
import l1j.server.server.clientpackets.C_ExtraCommand;
import l1j.server.server.clientpackets.C_Fight;
import l1j.server.server.clientpackets.C_FishClick;
import l1j.server.server.clientpackets.C_FixWeaponList;
import l1j.server.server.clientpackets.C_GiveItem;
import l1j.server.server.clientpackets.C_HireSoldier;
import l1j.server.server.clientpackets.C_ItemUSe;
import l1j.server.server.clientpackets.C_JoinClan;
import l1j.server.server.clientpackets.C_KeepALIVE;
import l1j.server.server.clientpackets.C_LeaveClan;
import l1j.server.server.clientpackets.C_LeaveParty;
import l1j.server.server.clientpackets.C_LoginToServer;
import l1j.server.server.clientpackets.C_LoginToServerOK;
import l1j.server.server.clientpackets.C_Mail;
import l1j.server.server.clientpackets.C_MoveChar;
import l1j.server.server.clientpackets.C_NPCAction;
import l1j.server.server.clientpackets.C_NPCTalk;
import l1j.server.server.clientpackets.C_NewCharSelect;
import l1j.server.server.clientpackets.C_Party;
import l1j.server.server.clientpackets.C_PetMenu;
import l1j.server.server.clientpackets.C_PickUpItem;
import l1j.server.server.clientpackets.C_Pledge;
import l1j.server.server.clientpackets.C_Propose;
import l1j.server.server.clientpackets.C_Rank;
import l1j.server.server.clientpackets.C_Restart;
import l1j.server.server.clientpackets.C_Result;
import l1j.server.server.clientpackets.C_ReturnToLogin;
import l1j.server.server.clientpackets.C_SelectList;
import l1j.server.server.clientpackets.C_SelectTarget;
import l1j.server.server.clientpackets.C_SendLocation;
import l1j.server.server.clientpackets.C_ServerVersion;
import l1j.server.server.clientpackets.C_Ship;
import l1j.server.server.clientpackets.C_Shop;
import l1j.server.server.clientpackets.C_ShopList;
import l1j.server.server.clientpackets.C_SkillBuy;
import l1j.server.server.clientpackets.C_SkillBuyOK;
import l1j.server.server.clientpackets.C_TaxRate;
import l1j.server.server.clientpackets.C_Teleport;
import l1j.server.server.clientpackets.C_Title;
import l1j.server.server.clientpackets.C_Trade;
import l1j.server.server.clientpackets.C_TradeAddItem;
import l1j.server.server.clientpackets.C_TradeCancel;
import l1j.server.server.clientpackets.C_TradeOK;
import l1j.server.server.clientpackets.C_UsePetItem;
import l1j.server.server.clientpackets.C_UseSkill;
import l1j.server.server.clientpackets.C_War;
import l1j.server.server.clientpackets.C_WarePassword;
import l1j.server.server.clientpackets.C_Who;

public class PacketHandler {

	public PacketHandler(final ClientThread client) {
		_client = client;
	}

	public void handlePacket(final byte abyte0[])throws Exception {
		final int i = abyte0[0] & 0xff;
		//System.out.println("[Client] opcode = " + i);
		/*if(object!=null){
		System.out.println(object.getName()+"[Client] opcode = " + i+"  "+(new Timestamp(System.currentTimeMillis())));
		}else{
			System.out.println("[Client] opcode = " + i);	
		}*/
		switch (i) {
		case C_OPCODE_EXCLUDE:
			new C_Exclude().start(abyte0, _client);
			break;

		case C_OPCODE_CHARACTERCONFIG:
			new C_CharcterConfig().start(abyte0, _client);
			break;

		case C_OPCODE_DOOR:
			new C_Door().start(abyte0, _client);
			break;

		case C_OPCODE_TITLE:
			new C_Title().start(abyte0, _client);
			break;

		case C_OPCODE_BOARDDELETE:
			new C_BoardDelete().start(abyte0, _client);
			break;

		case C_OPCODE_PLEDGE:
			new C_Pledge().start(abyte0, _client);
			break;

		case C_OPCODE_CHANGEHEADING:
			new C_ChangeHeading().start(abyte0, _client);
			break;

		case C_OPCODE_NPCACTION:
			new C_NPCAction().start(abyte0, _client);
			break;

		case C_OPCODE_USESKILL:
			new C_UseSkill().start(abyte0, _client);
			break;

		case C_OPCODE_EMBLEM:
			new C_Emblem().start(abyte0, _client);
			break;

		case C_OPCODE_TRADEADDCANCEL:
			new C_TradeCancel().start(abyte0, _client);
			break;

		case C_OPCODE_CHANGEWARTIME:
			new C_ChangeWarTime().start(abyte0, _client);
			break;

		case C_OPCODE_BOOKMARK://TODO 要求增加記憶座標
			new C_AddBookmark().start(abyte0, _client);
			break;

		case C_OPCODE_CREATECLAN:
			new C_CreateClan().start(abyte0, _client);
			break;

		case C_OPCODE_CLIENTVERSION:
			new C_ServerVersion().start(abyte0, _client);
			break;

		case C_OPCODE_PROPOSE:
			new C_Propose().start(abyte0, _client);
			break;

		case C_OPCODE_SKILLBUY:
			new C_SkillBuy().start(abyte0, _client);
			break;

		case C_OPCODE_BOARDNEXT://TODO 修正無法使用指令的錯誤封包
			new C_BoardBack().start(abyte0, _client);
			break;

		case C_OPCODE_SHOP:
			new C_Shop().start(abyte0, _client);
			break;

		case C_OPCODE_BOARDREAD:
			new C_BoardRead().start(abyte0, _client);
			break;

		case C_OPCODE_TRADE:
			new C_Trade().start(abyte0, _client);
			break;

		case C_OPCODE_DELETECHAR:
			new C_DeleteChar().start(abyte0, _client);
			break;

		case C_OPCODE_KEEPALIVE:
			new C_KeepALIVE().start(abyte0, _client);
			break;

		case C_OPCODE_ATTR:
			new C_Attr().start(abyte0, _client);
			break;

		case C_OPCODE_LOGINPACKET:
			new C_AuthLogin().start(abyte0, _client);
			break;

		case C_OPCODE_RESULT:
			new C_Result().start(abyte0, _client);
			break;

		case C_OPCODE_DEPOSIT:
			new C_Deposit().start(abyte0, _client);
			break;

		case C_OPCODE_DRAWAL:
			new C_Drawal().start(abyte0, _client);
			break;

		case C_OPCODE_LOGINTOSERVEROK:
			new C_LoginToServerOK().start(abyte0, _client);
			break;

		case C_OPCODE_SKILLBUYOK:
			new C_SkillBuyOK().start(abyte0, _client);
			break;

		case C_OPCODE_TRADEADDITEM:
			new C_TradeAddItem().start(abyte0, _client);
			break;

		case C_OPCODE_ADDBUDDY:
			new C_AddBuddy().start(abyte0, _client);
			break;

		case C_OPCODE_RETURNTOLOGIN://TODO 要求回到選人畫面
			new C_ReturnToLogin().start(abyte0, _client);
			break;

		case C_OPCODE_CHAT:
			new C_Chat().start(abyte0, _client);
			break;

		case C_OPCODE_TRADEADDOK:
			new C_TradeOK().start(abyte0, _client);
			break;

		case C_OPCODE_CHECKPK:
			new C_CheckPK().start(abyte0, _client);
			break;

		case C_OPCODE_TAXRATE:
			new C_TaxRate().start(abyte0, _client);
			break;

		case C_OPCODE_CHANGECHAR:
			new C_NewCharSelect().start(abyte0, _client);
			break;

		case C_OPCODE_BUDDYLIST:
			new C_Buddy().start(abyte0, _client);
			break;

		case C_OPCODE_DROPITEM:
			new C_DropItem().start(abyte0, _client);
			break;

		case C_OPCODE_LEAVEPARTY:
			new C_LeaveParty().start(abyte0, _client);
			break;

		case C_OPCODE_ATTACK:
			new C_Attack().start(abyte0, _client);
			break;
			
		case C_OPCODE_ARROWATTACK:
			new C_Attack().start(abyte0, _client);
			break;

		// キャラクターのショートカットやインベントリの状態がプレイ中に変動した場合に
		// ショートカットやインベントリの状態を付加してクライアントから送信されてくる
		// 送られてくるタイミングはクライアント終了時
		case C_OPCODE_QUITGAME:
			break;

		case C_OPCODE_BANCLAN:
			new C_BanClan().start(abyte0, _client);
			break;

		case C_OPCODE_BOARD:
			new C_Board().start(abyte0, _client);
			break;

		case C_OPCODE_DELETEINVENTORYITEM:
			new C_DeleteInventoryItem().start(abyte0, _client);
			break;

		case C_OPCODE_CHATWHISPER:
			new C_ChatWhisper().start(abyte0, _client);
			break;

		case C_OPCODE_PARTYLIST://TODO 查看隊伍封包修正
			new C_Party().start(abyte0, _client);
			break;

		case C_OPCODE_PICKUPITEM:
			new C_PickUpItem().start(abyte0, _client);
			break;

		case C_OPCODE_WHO:
			new C_Who().start(abyte0, _client);
			break;

		case C_OPCODE_GIVEITEM:
			new C_GiveItem().start(abyte0, _client);
			break;

		case C_OPCODE_MOVECHAR:
			new C_MoveChar(abyte0, _client);
			break;

		case C_OPCODE_BOOKMARKDELETE://TODO 要求刪除記憶座標
			new C_DeleteBookmark().start(abyte0, _client);
			break;

		case C_OPCODE_RESTART:
			new C_Restart().start(abyte0, _client);
			break;

		case C_OPCODE_LEAVECLANE:
			new C_LeaveClan().start(abyte0, _client);
			break;

		case C_OPCODE_NPCTALK:
			new C_NPCTalk().start(abyte0, _client);
			break;

		case C_OPCODE_BANPARTY:
			new C_BanParty().start(abyte0, _client);
			break;

		case C_OPCODE_DELETEBUDDY://TODO 3.52C請求刪除好友
			new C_DelBuddy().start(abyte0, _client);
			break;

		case C_OPCODE_WAR:
			new C_War().start(abyte0, _client);
			break;

		case C_OPCODE_LOGINTOSERVER:
			new C_LoginToServer().start(abyte0, _client);
			break;

		case C_OPCODE_PRIVATESHOPLIST:
			new C_ShopList().start(abyte0, _client);
			break;

		case C_OPCODE_CHATGLOBAL:
			new C_Chat().start(abyte0, _client);
			break;

		case C_OPCODE_JOINCLAN:
			new C_JoinClan().start(abyte0, _client);
			break;

		case C_OPCODE_COMMONCLICK:
			new C_CommonClick().start(abyte0 ,_client);
			break;

		case C_OPCODE_NEWCHAR:
			new C_CreateChar().start(abyte0, _client);
			break;

		case C_OPCODE_EXTCOMMAND:
			new C_ExtraCommand().start(abyte0, _client);
			break;

		case C_OPCODE_BOARDWRITE:
			new C_BoardWrite().start(abyte0, _client);
			break;

		case C_OPCODE_USEITEM:
			new C_ItemUSe().start(abyte0, _client);
			break;

		case C_OPCODE_CREATEPARTY:
			new C_CreateParty().start(abyte0, _client);
			break;

		case C_OPCODE_ENTERPORTAL://TODO 3.5C要求傳送 (進入地監)封包修正by99團隊
			new C_EnterPortal().start(abyte0, _client);
			break;

		case C_OPCODE_AMOUNT:
			new C_Amount().start(abyte0, _client);
			break;

		case C_OPCODE_FIX_WEAPON_LIST:
			new C_FixWeaponList().start(abyte0, _client);
			break;

		case C_OPCODE_SELECTLIST://TODO 請求修理道具
			new C_SelectList().start(abyte0, _client);
			break;

		case C_OPCODE_EXIT_GHOST:
			new C_ExitGhost().start(abyte0, _client);
			break;

		case C_OPCODE_CALL://TODO 要求召喚到身邊(GM)
			new C_CallPlayer().start(abyte0, _client);
			break;

		case C_OPCODE_HIRESOLDIER:
			new C_HireSoldier().start(abyte0, _client);
			break;

		case C_OPCODE_FISHCLICK:
			new C_FishClick().start(abyte0, _client);
			break;

		case C_OPCODE_SELECTTARGET:
			new C_SelectTarget().start(abyte0, _client);
			break;

		case C_OPCODE_PETMENU:
			new C_PetMenu().start(abyte0, _client);
			break;

		case C_OPCODE_USEPETITEM:
			new C_UsePetItem().start(abyte0, _client);
			break;

		case C_OPCODE_TELEPORT:
			new C_Teleport().start(abyte0, _client);
			break;

		case C_OPCODE_RANK://TODO 請求給予角色血盟階級
			new C_Rank().start(abyte0, _client);
			break;

		case C_OPCODE_CAHTPARTY:
			new C_ChatParty().start(abyte0, _client);
			break;

		case C_OPCODE_FIGHT:
			new C_Fight().start(abyte0, _client);
			break;

		case C_OPCODE_SHIP:
			new C_Ship().start(abyte0, _client);
			break;

		case C_OPCODE_MAIL:
			new C_Mail().start(abyte0, _client);
			break;

		case C_OPCODE_CHARRESET:
			new C_CharReset().start(abyte0, _client);
			break;

		case C_OPCODE_CLAN:
			new C_Clan().start(abyte0, _client);
			break;
			
		//TODO 要求傳送位置(3.3C 新增)封包修正
		case C_OPCODE_SENDLOCATION:
			new C_SendLocation().start(abyte0, _client);
			break;
		//TODO 要求傳送位置(3.3C 新增)封包修正
			
		case C_OPCODE_WAREHOUSELOCK:
			new C_WarePassword().start(abyte0, _client);
			break;

		default:
			// String s = Integer.toHexString(abyte0[0] & 0xff);
			// _log.warning("用途不明オペコード:データ内容");
			// _log.warning((new StringBuilder()).append("オペコード ").append(s)
			// .toString());
			// _log.warning(new ByteArrayUtil(abyte0).dumpToString());
			break;
		}
		// _log.warning((new StringBuilder()).append("オペコード
		// ").append(i).toString());
	}

	private final ClientThread _client;
}